package cn.kgc.dao.impl;

import cn.kgc.dao.BaseDao;
import cn.kgc.dao.LoginDao;
import cn.kgc.entity.Admin;
import cn.kgc.entity.Student;
import cn.kgc.entity.Teacher;

import java.util.List;

public class LoginImpl extends BaseDao implements LoginDao {
    @Override
    public Student studentLogin(String account,String stunum) {
        Student  student=null;
        String sql="SELECT * FROM school_student WHERE name=?AND stunum=?";
        List<Student> sList = this.query(Student.class,sql, account, stunum);
        if (sList!=null&&sList.size()>0){
            student=sList.get(0);
        }
        return student;
    }

    @Override
    public Teacher teacherLogin(String account, String jobnum) {
        Teacher teacher=null;
        String sql="SELECT * FROM school_teacher WHERE name=? AND jobnum=?";
        List<Teacher> sList = this.query(Teacher.class,sql, account, jobnum);
        if (sList!=null&&sList.size()>0){
            teacher=sList.get(0);
        }
        return teacher;
    }

    @Override
    public Admin adminLogin(String account,String password) {
        Admin admin=null;
        String sql="SELECT * FROM school_admin WHERE account=? AND PASSWORD=?";
        List<Admin> sList = this.query(Admin.class,sql, account, password);
        if (sList!=null&&sList.size()>0){
            admin=sList.get(0);
        }
        return admin;
    }
}
